<?php


/** ensure this file is being included by a parent file */
defined('_JEXEC') or die('Restricted access');
?>

		<?php
		echo "<form action='{$this->formAction}' method='post' name='adminForm' id='adminForm'>";
		?>
		<div class='componentheading'>
            <?php if (!empty($this->pagetitle)) { echo $this->pagetitle; } ?>
		</div>
		
		<table class="invisible">
		<tr>
			<td class="title">
				<?php 
				echo "<a href='".HelpDeskRoute::_('index.php?option=com_helpdesk&controller=tickets&task=new&Itemid='.$this->Itemid )."'>";
				echo "<img src='".HelpDeskUrl::root()."/components/com_helpdesk/images/newticket.png' align='center' border='0'>"; 
				echo "</a>"; 
				?>
			</td>
			<td class='input' nowrap='nowrap'>
				<?php 
				echo "<a href='".HelpDeskRoute::_('index.php?option=com_helpdesk&controller=tickets&task=new&Itemid='.$this->Itemid )."'>";
				echo HelpDeskText::_( 'New Ticket' ); 
				echo "</a>"; 
				?>
			</td>
			<td style="width: 50%;">&nbsp;</td>       
			<td class='right'>
				<?php echo HelpDeskText::_( 'Search' ); ?>:
			</td>
			<td class="input">
				<?php echo $this->search; ?>
			</td>
      		<?php
				for ($f=0; $f<count($this->filterLists); $f++) {
		          	echo "<td class='right'>";
					echo $this->filterLists[$f];
					echo "</td>";
				}
			?>
		</tr>
		</table>

		<table class="userlist">
		<thead>
            <tr>
                <th width='25px' style='max-width: 25px; vertical-align: middle;'>
                	<?php echo HelpDeskHTML::sortList( HelpDeskText::_( 'ID' ), "id", $this->order_dir, $this->order, HelpDeskRequest::getVar( 'task' ) ); ?>
                </th>                
                <th class="title" style="width: 40%">
                	<?php echo HelpDeskHTML::sortList( HelpDeskText::_( 'Subject' ), "subject", $this->order_dir, $this->order, HelpDeskRequest::getVar( 'task' ) ); ?>
                	+
                	<?php echo HelpDeskHTML::sortList( HelpDeskText::_('Category'), "categoryid", $this->order_dir, $this->order, HelpDeskRequest::getVar( 'task' ) ); ?>
                </th>
                <th class="title">
                	<center>
	                <?php echo HelpDeskHTML::sortList( HelpDeskText::_( 'Last Modified' ), "lastmodified", $this->order_dir, $this->order, HelpDeskRequest::getVar( 'task' ) ); ?><br />
	                <?php echo HelpDeskHTML::sortList( HelpDeskText::_( 'and' )." ".HelpDeskText::_( 'Created Date' ), "created", $this->order_dir, $this->order, HelpDeskRequest::getVar( 'task' ) ); ?>
	                </center>
                </th>
                <th class="title">
                	<center>
	                <?php echo HelpDeskHTML::sortList( HelpDeskText::_( 'Status' ), "status", $this->order_dir, $this->order, HelpDeskRequest::getVar( 'task' ) ); ?>
	                </center>
                </th>
                <th class="title">
                	<center>
	                <?php echo HelpDeskText::_( 'Feedback' ); ?>
	                </center>
                </th>
            </tr>
		</thead>
        <tbody>
		<?php
        $k = 0;
		$today 			= date( "Y-m-d" );
		$yesterday_time	= time() - (24 * 60 * 60); // timestamp - 24 hours * 60 mins * 60secs
		$yesterday		= date( "Y-m-d", $yesterday_time ); 
        for ($i=0, $n=count( $this->items ); $i < $n; $i++)
        {
            $r =& $this->items[$i];
            $checked    = HelpDeskHTML::gridId( $i, $r->id );
        	$published 	= HelpDeskHTML::gridPublished( $r, $i );
            $link = HelpDeskRoute::_( 'index.php?option='.$option.'&controller='.$this->_name.'&task=view&cid[]='. $r->id );

            $last_modified 	= HelpDeskHTML::date($r->last_modified_datetime, "%a, %d %b %Y");
            $created 		= HelpDeskHTML::date($r->created_datetime, "%a, %d %b %Y");
    
	        echo "<tr class='row".$k."'>";
	            echo "<td class='noborder'>"; echo "<a href='".$link."'>$r->id</a>"; echo "</td>";
	            echo "<td class='noborder'>";
	            
	                echo "<a href='".$link."'>"; 
	                echo "<strong>";
	                echo stripslashes($r->subject);
	                echo "</strong>";
	               
	                echo "<br/>";
	                 
	                echo HelpDeskText::_( $r->categoryname );
	                echo "</a>";
	            echo "</td>";
	            echo "<td class='noborder' nowrap><center>";
	                if ($last_modified == $today) {
	                    echo HelpDeskHTML::date($r->last_modified_datetime, "%I:%M%p"); // strftime formatting
	                } elseif ($last_modified == $yesterday) {
	                    echo HelpDeskText::_( 'Yesterday' ).", ".HelpDeskHTML::date($r->last_modified_datetime, "%I:%M%p"); // strftime formatting
	                } else {
	                    echo HelpDeskHTML::date($r->last_modified_datetime, "%a, %d %b %Y, %I:%M%p"); // strftime formatting
	                }
	                
	                echo "<br />---<br />";
	
	                if ($created == $today) {
	                    echo HelpDeskHTML::date($r->created_datetime, "%I:%M%p"); // strftime formatting
	                } elseif ($created == $yesterday) {
	                    echo HelpDeskText::_( 'Yesterday' ).", ".HelpDeskHTML::date($r->created_datetime, "%I:%M%p"); // strftime formatting
	                } else {
	                    echo HelpDeskHTML::date($r->created_datetime, "%a, %d %b %Y, %I:%M%p"); // strftime formatting
	                }
	            echo "</center></td>";
	            echo "<td class='noborder'><center>"; 
	                echo HelpDeskHelperHelpDesk::getTicketStatusImage($r->status);
	                echo "<br />".HelpDeskHelperHelpDesk::getTicketStatus($r->status);
	            echo "</center></td>";
	            echo "<td class='noborder'><center>"; 
	            	echo HelpDeskHelperHelpDesk::getFeedbackRatingImage($r->feedback_rating);
        	        if ($r->status == 2) {
		            	echo "<br />";
		            	echo HelpDeskHTML::date($r->feedback_datetime, "%a, %d %b %Y, %I:%M%p"); 					
	                }
	            echo "</center></td>";
	        echo "</tr>";
        
            if (isset($r->description) && strlen($r->description) > 1)  
			{ 
		        echo "<tr class='row".$k."'>";
	            echo "<td class='topnowrap' valign='top' nowrap>";
					$text_display = "[ + ]";
					$text_hide = "[ - ]";
					$onclick = "displayDiv(\"description_{$r->id}\", \"showhidedescription_{$r->id}\", \"{$text_display}\", \"{$text_hide}\");";
					echo "<span class='href' id='showhidedescription_{$r->id}' onclick='{$onclick}'>{$text_display}</span>";
	            echo "</td>";
	            echo "<td colspan='10'>"; 
					echo "<div id='description_{$r->id}' style='display: none;'>";
					echo nl2br( stripslashes( $r->description ) );
					echo "</div>";
	            echo "</td>";
		        echo "</tr>";
			}
        	$k = 1 - $k;
        }
		
		if (!$this->items) {
			echo "<tr class='row".$k."'>";
				echo "<td class='topnowrap' colspan='10'>";
				echo HelpDeskText::_( 'None' );
				echo "</td>";
			echo "</tr>";		
		}
        ?>
        </tbody>
        <tfoot>
        	<tr>
                <td colspan='10'>
                    <div class="pagination">
                    <?php echo $this->pagination->getListFooter(); ?>
                    </div>            
                </td>
            </tr>
        </tfoot>

		</table>
		
		<input type="hidden" name="Itemid" value="<?php echo $this->Itemid; ?>" />
		
		<input type="hidden" name="option" value="<?php echo $this->formOption; ?>" />
		<input type="hidden" name="controller" value="<?php echo $this->formController; ?>" />
		<input type="hidden" name="task" value="" />
		<input type="hidden" name="id" value="" />
		<input type="hidden" name="boxchecked" value="" />
		<input type="hidden" name="order" value="<?php echo $this->order; ?>" />
		<input type="hidden" name="order_dir" value="<?php echo $this->order_dir; ?>" />
        
		<?php
		echo $this->formValidate;
		echo "</form>";
		?>